﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Collections.Generic;

namespace ExcelMapper.Test
{
    [TestClass]
    public class ExcelClassTest
    {
        [TestMethod]
        public void BasicConstructorTest()
        {
            var path = Directory.GetCurrentDirectory();
            string filePath = path + @"\FakeData\ExcelFake.xlsx";
            var excelClass = new ExcelDocument(filePath);
            var result = excelClass.Load();
            var resultExtra = excelClass.GetDocumentValues();
            var resultHeaders = excelClass.GetHeaders();
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(List<IDictionary<string, object>>));
            Assert.AreEqual(1, excelClass.RowHeader);
            Assert.AreEqual(1, excelClass.SheetPage);
            Assert.AreEqual(0, excelClass.PreRowHeader);
            Assert.AreEqual(null, excelClass.Name);
            Assert.AreEqual(filePath, excelClass.PathFile);
            Assert.AreEqual(10, result.Count);
            Assert.IsNotNull(resultExtra);
            Assert.IsInstanceOfType(resultExtra, typeof(List<IDictionary<string, object>>));
            Assert.AreEqual(10, resultExtra.Count);
            Assert.AreEqual(result, resultExtra);
            Assert.IsInstanceOfType(resultHeaders, typeof(List<string>));
            Assert.AreEqual(10, resultHeaders.Count);


        }

        [TestMethod]
        public void Constructor_Three_parameters_Test()
        {
            var path = Directory.GetCurrentDirectory();
            string filePath = path + @"\FakeData\ExcelFake.xlsx";
            var excelClass = new ExcelDocument(filePath,1,0);
            var result = excelClass.Load();
            var resultExtra = excelClass.GetDocumentValues();
            var resultHeaders = excelClass.GetHeaders();
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(List<IDictionary<string, object>>));
            Assert.AreEqual(1, excelClass.RowHeader);
            Assert.AreEqual(1, excelClass.SheetPage);
            Assert.AreEqual(0, excelClass.PreRowHeader);
            Assert.AreEqual(null, excelClass.Name);
            Assert.AreEqual(filePath, excelClass.PathFile);
            Assert.AreEqual(10, result.Count);
            Assert.IsNotNull(resultExtra);
            Assert.IsInstanceOfType(resultExtra, typeof(List<IDictionary<string, object>>));
            Assert.AreEqual(10, resultExtra.Count);
            Assert.AreEqual(result, resultExtra);
            Assert.IsInstanceOfType(resultHeaders, typeof(List<string>));
            Assert.AreEqual(10, resultHeaders.Count);


        }

        [TestMethod]
        public void Constructor_Four_parameters_Test()
        {
            var path = Directory.GetCurrentDirectory();
            string filePath = path + @"\FakeData\ExcelFake.xlsx";
            var excelClass = new ExcelDocument(filePath, 1, 0,"BasicFile");
            var result = excelClass.Load();
            var resultExtra = excelClass.GetDocumentValues();
            var resultHeaders = excelClass.GetHeaders();
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(List<IDictionary<string, object>>));
            Assert.AreEqual(1, excelClass.RowHeader);
            Assert.AreEqual(1, excelClass.SheetPage);
            Assert.AreEqual(0, excelClass.PreRowHeader);
            Assert.AreEqual("BasicFile", excelClass.Name);
            Assert.AreEqual(filePath, excelClass.PathFile);
            Assert.AreEqual(10, result.Count);
            Assert.IsNotNull(resultExtra);
            Assert.IsInstanceOfType(resultExtra, typeof(List<IDictionary<string, object>>));
            Assert.AreEqual(10, resultExtra.Count);
            Assert.AreEqual(result, resultExtra);
            Assert.IsInstanceOfType(resultHeaders, typeof(List<string>));
            Assert.AreEqual(10, resultHeaders.Count);


        }

    }
}
